package com.hingstd.lastwork.controllers;

import com.hingstd.lastwork.dao.SignRepository;
import com.hingstd.lastwork.dao.WarnRepository;
import com.hingstd.lastwork.entities.Sign;
import com.hingstd.lastwork.entities.Warn;
import com.hingstd.lastwork.services.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("signs")
public class SignController {

    @Autowired
    SignService signService;

    @GetMapping("new")
    public String displaySignForm(Model model){

        Sign aSign = new Sign();
        model.addAttribute("sign", aSign);
        return "home";
    }

    @PostMapping("/save")
    public String createSign(Model model, Sign sign){
        //处理保存数据库
        signService.save(sign);

        return "redirect:/";
    }
}
